package com.rqf.ls.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.rqf.ls.service.IEvaluationService;
import com.rqf.ls.service.IQuestionAnswerService;
import com.server.web.JSONSerielizer;
import com.server.web.OutputUtil;

@Controller
@RequestMapping("evaluation")
public class EvaluationController {

	@Autowired
	private IEvaluationService evaluationService;
	@Autowired
	private IQuestionAnswerService questionAnswerService;
	
	 /**
	 * 增加评价
	 * @param request
	 * @param response
	 * @param phoneNo
	 * @author ServerZhang
	 * @date 2016年3月29日
	 */
	@RequestMapping("add/{phoneNo}")
	public void add(HttpServletRequest request, 
			HttpServletResponse response,@PathVariable String phoneNo){
		String content = request.getParameter("content");
		String anwserid = request.getParameter("anwserid");
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("phoneNo", phoneNo);
		map.put("content", content);
		map.put("anwserid", anwserid);
		
		Boolean isSuccess = evaluationService.add(map);
		OutputUtil.returnJsonp(request, response, isSuccess.toString());
	}
	
	 /**
	 * 评价列表
	 * @param request
	 * @param response
	 * @param phoneNo
	 * @author ServerZhang
	 * @date 2016年3月29日
	 */
	@RequestMapping("list/{phoneNo}")
	public void list(HttpServletRequest request, 
			HttpServletResponse response,@PathVariable String phoneNo){
		List<Map<String, Object>> list = evaluationService.getList(phoneNo);
		String json = JSONSerielizer.toJson(list, null, null);
		OutputUtil.returnJsonp(request, response, json);
	}
	
	/**
	 * 评价律师回答
	 * @param request
	 * @param response
	 * @author HelloWorld_Luo
	 * @date 2016年9月19日
	 */
	@RequestMapping("evaluateAnswer")
	public void evaluate(HttpServletRequest request, 
			HttpServletResponse response){
		String EVA01 = request.getParameter("EVA01");
		String CONTENT01 = request.getParameter("CONTENT01");
		String EVA02 = request.getParameter("EVA02");
		String CONTENT02 = request.getParameter("CONTENT02");
		String EVA03 = request.getParameter("EVA03");
		String CONTENT03 = request.getParameter("CONTENT03");
		
		String QUESTIONID = request.getParameter("QUESTIONID");
		String ANSWERID = request.getParameter("ANSWERID");
		String LAWYERPHONE = request.getParameter("LAWYERPHONE");
		String USERPHONE = request.getParameter("USERPHONE");
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("EVA01", EVA01);
		map.put("CONTENT01", CONTENT01);
		map.put("EVA02", EVA02);
		map.put("CONTENT02", CONTENT02);
		map.put("EVA03", EVA03);
		map.put("CONTENT03", CONTENT03);
		map.put("QUESTIONID", QUESTIONID);
		map.put("ANSWERID", ANSWERID);
		map.put("LAWYERPHONE", LAWYERPHONE);
		map.put("USERPHONE", USERPHONE);
		
		Boolean isSuccess = evaluationService.addEvaluate(map);
		
		if ( isSuccess ) {
			Map<String, Object> inputMap = new HashMap<String, Object>();
			inputMap.put("ISEVALUATE", 1);
			isSuccess = questionAnswerService.updateAnswer(Integer.parseInt(ANSWERID), inputMap);
		}
		OutputUtil.returnJsonp(request, response, isSuccess.toString());
	}
	
}
